package com.snailhd.cloud.account.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.UUID;

@Data
public class TokenDTO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	//用户id
	private long id;

	//随机数
	private String nonceStr;

	//登录时间
	private long loginTime;

	//登录设备类型
	private Integer logindeviceType;
	
	public TokenDTO() {}

	public static TokenDTO getInstance(long id) {
		TokenDTO token = new TokenDTO();
		token.setId(id);
		token.setNonceStr(UUID.randomUUID().toString().replace("-", ""));
		token.setLoginTime(System.currentTimeMillis());
		return token;
	}
	
	/**
	 * token 有效的
	 * @return
	 */
	public boolean isEffective(int effectiveMin) {
		return System.currentTimeMillis() < loginTime+effectiveMin*60*1000;
	}


}
